package com.jt.tenant.adapter;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.jt.tenant.R;
import com.jt.tenant.app.JTApplication;
import com.jt.tenant.conn.GetQueryFence;
import com.jt.tenant.widget.Tools;

import java.util.List;

/**
 * Created by Administrator on 2016/2/14.
 */
public class FenceAdapter extends BaseAdapter {

    private LayoutInflater layoutInflater;

    private View titleView;

    private List<GetQueryFence.Fence> list;

    public FenceAdapter(Context context,List<GetQueryFence.Fence> list){

        this.layoutInflater = ((Activity)context).getLayoutInflater();

        this.list = list;

    }

    @Override
    public int getCount() {

        return list.size();

    }

    @Override
    public Object getItem(int position) {

        return null;

    }

    @Override
    public long getItemId(int position) {

        return 0;

    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {

        ViewHolder viewHolder;

        if (convertView == null){

            convertView = JTApplication.ScaleScreenHelper.loadView((ViewGroup) layoutInflater.inflate(R.layout.item_fence, null));

            viewHolder = new ViewHolder();

            viewHolder.name = (TextView) convertView.findViewById(R.id.fence_name);

            viewHolder.tracktime = (TextView)convertView.findViewById(R.id.fence_time);

            viewHolder.trackrange = (TextView)convertView.findViewById(R.id.fence_range);

            convertView.setTag(viewHolder);

        }else{

            viewHolder = (ViewHolder) convertView.getTag();

        }

        if (position < list.size() - 1){

            convertView.setBackgroundColor(Color.WHITE);

        }else{

            convertView.setBackgroundResource(R.drawable.bian_bottom_c4c4c4_ffffff);

        }

        viewHolder.name.setText(list.get(position).name);

        if(!list.get(position).createTime.equals("")){

            viewHolder.tracktime.setText(Tools.getTime2(list.get(position).createTime));

        }

        viewHolder.trackrange.setText("范围: "+ list.get(position).rangeNum+"公里");

        return convertView;

    }

    @Override
    public void notifyDataSetChanged() {

        super.notifyDataSetChanged();

    }


    private class ViewHolder{

        private TextView name;

        private TextView tracktime;

        private TextView trackrange;
    }

}
